<?php

require_once './jicunbao.php';
require_once './gfun.php';

$server = new swoole_server("0.0.0.0", 9508, SWOOLE_PROCESS, SWOOLE_SOCK_UDP);//测试端口9508；正式端口9502

//UDP监听数据发送事件
$server->on('Packet', function ($serv, $data, $clientInfo){
	$msg=date("9508---Y-m-d H:i:s",time())."----".$clientInfo['address']."|".$clientInfo['port']."Received:".gfun::strtohex($data)."\n";
	echo $msg;
	$send = jicunbao::index($data,$clientInfo);
	
	if(!empty($send)){
		if(is_array($send)){
			$count=1;
			foreach($send as $da){
				// $msg=date("Y-m-d H:i:s")."----".$clientInfo['address']."|".$clientInfo['port']."Send".$count.":".$da."\n";
				// echo $msg;
				$serv->sendto($clientInfo['address'], $clientInfo['port'], gfun::hextostr($da),$clientInfo['server_socket']);
				$count++;
			}
		}
		else
		{
			// $msg=date("Y-m-d H:i:s")."----".$clientInfo['address']."|".$clientInfo['port']."Send:".$send."\n";
			// echo $msg;
			$serv->sendto($clientInfo['address'], $clientInfo['port'], gfun::hextostr($send),$clientInfo['server_socket']);
		}
	}
});

//启动服务器
$server->start();

